/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.qx.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.qx.entity.QxMontiorRule;
import com.thinkgem.jeesite.modules.qx.service.QxMontiorRuleService;

/**
 * 单表生成Controller
 * @author zequs
 * @version 2017-08-23
 */
@Controller
@RequestMapping(value = "${adminPath}/qx/qxMontiorRule")
public class QxMontiorRuleController extends BaseController {

	@Autowired
	private QxMontiorRuleService qxMontiorRuleService;
	
	@ModelAttribute
	public QxMontiorRule get(@RequestParam(required=false) String id) {
		QxMontiorRule entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = qxMontiorRuleService.get(id);
		}
		if (entity == null){
			entity = new QxMontiorRule();
		}
		return entity;
	}
	
	@RequiresPermissions("qx:qxMontiorRule:view")
	@RequestMapping(value = {"list", ""})
	public String list(QxMontiorRule qxMontiorRule, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<QxMontiorRule> page = qxMontiorRuleService.findPage(new Page<QxMontiorRule>(request, response), qxMontiorRule); 
		model.addAttribute("page", page);
		return "modules/qx/qxMontiorRuleList";
	}

	@RequiresPermissions("qx:qxMontiorRule:view")
	@RequestMapping(value = "form")
	public String form(QxMontiorRule qxMontiorRule, Model model) {
		model.addAttribute("qxMontiorRule", qxMontiorRule);
		return "modules/qx/qxMontiorRuleForm";
	}

	@RequiresPermissions("qx:qxMontiorRule:edit")
	@RequestMapping(value = "save")
	public String save(QxMontiorRule qxMontiorRule, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, qxMontiorRule)){
			return form(qxMontiorRule, model);
		}
		qxMontiorRuleService.save(qxMontiorRule);
		addMessage(redirectAttributes, "保存单表成功");
		return "redirect:"+Global.getAdminPath()+"/qx/qxMontiorRule/?repage";
	}
	
	@RequiresPermissions("qx:qxMontiorRule:edit")
	@RequestMapping(value = "delete")
	public String delete(QxMontiorRule qxMontiorRule, RedirectAttributes redirectAttributes) {
		qxMontiorRuleService.delete(qxMontiorRule);
		addMessage(redirectAttributes, "删除单表成功");
		return "redirect:"+Global.getAdminPath()+"/qx/qxMontiorRule/?repage";
	}

}